{include file="header/index" /}
		<div class="container whitebg add_new_user">
		    <h3 class="title">修改客户</h3>
			<h4 class="subtitle">主要信息</h4>
			<form class="form-horizontal" id="form">
					<input type="hidden" name="user_id" value="{$info.user_id}">
				<div class="form-group">
					<label class="col-sm-2 control-label">姓名</label>
					<div class="col-sm-4">
						<input type="text" name="username" class="form-control" placeholder="请输入真实姓名（商用客户请输入公司名称）" value="{$info.username}">
					</div>
					<i class="col-red">*</i>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">身份证号</label>
					<div class="col-sm-4">
						<input type="text" name="id_card" class="form-control" placeholder="请输入身份证号" value="{$info.id_card}">
					</div>
					<i class="col-red">*</i>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">生日</label>
					<div class="col-sm-4">
						<input type="text" name="birthday" readonly class="form_datetime form-control" placeholder="请选择时间" value="{$info.birthday}">
					</div>
					<i class="col-red">*</i>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">联系人电话</label>
					<div class="col-sm-4">
						<input type="text" name="telphone" class="form-control" placeholder="请输入联系人电话" value="{$info.telphone}">
					</div>
					<i class="col-red">*</i>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">当前推荐有效设备数</label>
					<div class="col-sm-4">
						<input type="text" name="number" class="form-control" placeholder="请输入推荐有效设备数" disabled value="{$info.number}">
					</div>
					<i class="col-red">*</i>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">是否入职</label>
						<div class="col-sm-3">
							<select name="is_entry" class="form-control" id="isentry" onchange="isEntry()">
								<option value="">选择是否入职</option>
								{volist name="is_entry" id="n" key="k"}
									<option value="{$k}" {if condition="((isset($info)) AND ($n == $info.is_entry))"}selected{/if}>{$n}</option>
								{/volist}
							</select>
						</div>
						
						<div class="col-sm-3 hides" id="personnelTime">
							<input type="text" name="personnel_time" id="personnel_time"  onchange="num()" {eq name="$info.is_set_entry" value="1"} readonly {/eq}  class="form_datetime form-control" placeholder="请输入员工就职时间" value="{$info.personnel_time}">
						</div>
						
						<div class="col-sm-3 hides" id="departureTime">
							<input type="text" name="departure_time" id="departure_time"  {eq name="$info.is_set_entry" value="3"} readonly {/eq}  class="form_datetime form-control" placeholder="请输入员工离职时间" value="{$info.departure_time}">
						</div>
						
						<div class="col-sm-3 hides" id="employeeId">
							<input type="text" name="employee_id" id="employee_id"  readonly class="form-control" placeholder="员工编号" value="{$info.employee_id}">
						</div>
						<div class="col-sm-3 hides" id="vip">
							<select name="user_type" class="form-control" id="vip">
								<option value="1" {if condition="((isset($info)) AND ($info.user_type=='普通用户'))"}selected{/if}>普通用户</option>
								<option value="2" {if condition="((isset($info)) AND ($info.user_type=='VIP用户'))"}selected{/if}>VIP用户</option>
							</select>
						</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">账户状态</label>
					<div class="col-sm-3">
						<select name="account_status" class="form-control">
							<option value="">选择账户状态</option>
							{volist name="status" id="n" key="k"}
								<option value="{$k}" {if condition="((isset($info)) AND ($n == $info.account_status))"}selected{/if}>{$n}</option>
							{/volist}
						</select>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">用户所属管理区域</label>
					<div class="col-sm-3">
						<select id="operation" name="operation_id" class="form-control" onChange="move()">
							{volist name="operation" id="op"}
							<option value="{$op.o_id}" {if condition='((isset($info)) AND ($op.o_id == $info.operation_id))'}selected{/if}>{$op.company_name}</option>
							{/volist}
						</select>
					</div>
					<div class="col-sm-3">
						<select id="administrative" name="a_id" class="form-control">
							{volist name="administrative" id="ad"}
							<option value="{$ad.a_id}" {if condition='((isset($info)) AND ($ad.a_id == $info.a_id))'}selected{/if}>{$ad.company_name}</option>
							{/volist}
						</select>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">用户地址</label>
					<div class="col-sm-2">
						<select id="_province" onchange="showcity()" class="form-control" name="province_code">
								{volist name="province" id="pr"}
								<option value="{$pr.id}" {if condition='((isset($info)) AND ($pr.id == $info.province_code))'}selected{/if}>{$pr.area_name}</option>
								{/volist}
						</select>
					</div>
					<div class="col-sm-2">
						<select id="_city" onchange="showarea()" class="form-control" name="city_code">
								{volist name="city" id="ci"}
								<option value="{$ci.id}" {if condition='((isset($info)) AND ($ci.id == $info.city_code))'}selected{/if}>{$ci.area_name}</option>
								{/volist}
						</select>
					</div>
					<div class="col-sm-2">
						<select id="_area" onchange="showareas()" class="form-control" name="area_code">
								<option value="0">--请选择区/县--</option>
								{volist name="area" id="ar"}
									{if condition='((isset($info)) AND ($ar.id == $info.area_code))'}
										<option value="{$ar.id}" {if condition='((isset($info)) AND ($ar.id == $info.area_code))'}selected{/if}>{$ar.area_name}</option>
									{else /}
										<option value="{$ar.id}">{$ar.area_name}</option>
									{/if}
								{/volist}
						</select>
					</div>
					<i class="col-red">*</i>				
				</div>
				<input type="hidden" name="province" value="{if condition='(isset($info))'}{$info.province}{/if}"/>
				<input type="hidden" name="city" value="{if condition='(isset($info))'}{$info.city}{/if}" />
				<input type="hidden" name="area" value="{if condition='(isset($info))'}{$info.area}{/if}" />
				
				<div class="form-group">
					<label class="col-sm-2 control-label">详细地址</label>
					<div class="col-sm-4">
						<input type="text" name="user_address" id="user_address" class="form-control" placeholder="请输入具体详细地址" value="{$info.user_address}">
					</div>
					<i class="col-red">*</i>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">备注</label>
					<div class="col-sm-6 Remarks" id="wordCount">
						<textarea name="remark" class="form-control" rows="5">{$info.remark}</textarea>
						<span class="wordwrap"><var class="word">500</var>/500</span>
					</div>
				</div>
			</form>
			<div>
				<label class="col-sm-2"></label>
				<button type="button" class="btn btn-primary mr30" id="but">保存</button>
				<!--<button type="button" class="btn btn-reset mr30" onclick="Resetmodel()">重置</button>-->
				<button class="btn btn-default" onclick="backurl()">返回</button>
			</div>

		</div>
	</body>

</html>
<script type="text/javascript">
	//返回上一页
	function backurl() {
		history.back();
	}

	//日期选择
	$(".form_datetime").datetimepicker({
		format: "yyyy-mm-dd",
		autoclose: true,
		minView: "month",
		todayBtn: true,
		pickerPosition: "bottom-left",
		language: 'cn'
	});

	
	// 根据选中的省获取对应的市
	function showcity(){
	    // 获取选中省对应的id 值
	    var id = $('#_province option:selected') .val();
        var province_name = $('#_province option:selected') .html();
	    $("input[name='province']").val(province_name);
	    // 发送ajax请求 获取对应的市
		$.getJSON("/admin/three/city.html",{parent_id:id},function(data){
			$("#_city").html('');
			var str = '<option value="0">--选择市--</option>';
			$.each(data,function(k,v){
			   str += '<option value="' + v.id + '">' + v.area_name + '</option>';
			});
			$("#_city").html(str);
			
			$("#_area").html('');
		   	var str = '<option value="0">--选择区/县--</option>';
		   	$("#_area").html(str);
		   	
		});
	}
	
	// 根据选中的市获取对应的区县
	function showarea() {
	    // 获取选中市对应的id 值
		var id = $('#_city option:selected').val();
		var city_name = $('#_city option:selected') .html();
		$("input[name='city']").val(city_name);

		// 发送ajax请求 获取对应的区县
		$.getJSON("/admin/three/areas.html",{city_id:id},function(data){
		   	$("#_area").html('');
		   	var str = '<option value="0">--选择区/县--</option>';
		   	$.each(data,function(k,v){
		   	   str += '<option value="' + v.id + '">' + v.area_name + '</option>';
			});
		   	$("#_area").html(str);
		});
	}
	
	function showareas(){
        var city_name = $('#_area option:selected') .html();
        $("input[name='area']").val(city_name);

	}


	//剩余字数统计
	$(function() {
		//先选出 textarea 和 统计字数 dom 节点
		var wordCount = $("#wordCount"),
			textArea = wordCount.find("textarea"),
			word = wordCount.find(".word");
		//调用
		statInputNum(textArea, word);
	});
	//注意 最大字数只需要在放数字的节点哪里直接写好即可 如：<var class="word">200</var>
	function statInputNum(textArea, numItem) {
		var max = numItem.text(),
			curLength;
		textArea[0].setAttribute("maxlength", max);
		curLength = textArea.val().length;
		numItem.text(max - curLength);
		textArea.on('input propertychange', function() {
			var _value = $(this).val().replace(/\n/gi, "");
			numItem.text(max - _value.length);
		});
	}
	
	//选择地址
	function move() {
		var operation = $("#operation").val();
//        console.log(operation);
		$.get("{:url('Customerinfo/selectAdministrative')}",{operation:operation},function (data) {
			$("#administrative").empty();
            $("#administrative").append($("<option>").val("").text("==所属行政中心=="));
            for (var i = 0;i<data.length;i++){
                var option = $("<option>").val(data[i].a_id).text(data[i].company_name);
                $("#administrative").append(option);
			}
        })
    }
	
	isEntry();
	//是否入职 departure_time
    var init_entry = true;
	function isEntry(){
		var k = $("#isentry option:selected").text();
		if(k=='入职'){
            init_entry = false;
			$("#vip").hide();
			$("#personnelTime").show();//入职
			$("#employeeId").show();
			$("#departureTime").hide();
			$("#departure_time").val('');
		}else if(k=='离职'){
			$("#vip").hide();
			$("#departureTime").show();//离职
			$("#employeeId").show();
			$("#personnelTime").hide();
			$("#personnel_time").val('');
		}else{
			$("#vip").show();
			$("#personnelTime").hide();//客户
			$("#departureTime").hide();
			$("#employeeId").hide();
			$("#personnel_time").val('');
			$("#departure_time").val('');
			$("#employee_id").val('');
		}
	}
	//
	function num(){
	    console.log(init_entry);
	    if (!init_entry){
            var num = {:EmployeeNumber()};
            $('#employee_id').val(num);
		}
	}
	naTure();
	//客户性质
	function naTure(){
		var k = $("#nature").val();
		if(k==1 || k==2){
			$("#userType").show();
		}else{
			$("#user_type").val("1");
			$("#userType").hide();
		}
	}
	
	$("#but").click(function () {
        var formData = new FormData($( "#form" )[0]);
        $.ajax({
            url:  "{:url('Customerinfo/doupdate')}",  /*这是处理文件上传的servlet*/
            type: 'POST',
            data: formData,
            async: false,
            cache: false,
            contentType: false,
            processData: false,
            dataType : 'json',
            success: function (returndata) {
                if (returndata.code == 0) {
                	//失败
                	top.layer.msg(returndata.msg, {icon: 1,time: 2000});
                }else{
                	//成功
                	top.layer.msg(returndata.msg, {icon: 1,time: 2000},function(){window.location.href=returndata.data});
				}

            },error: function (returndata) {
//            	top.layer.msg('数据异常', {icon: 2,time: 2000});
//				return false;
            }
        });
    });
	
	
	
	
	
	
	
	
	
	
	
	
	
</script>